package com.ruoyi.web.controller.comment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.comment.domain.SyComment;
import com.ruoyi.comment.service.ISyCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 评论Controller
 *
 * @author ruoyi
 * @date 2024-12-31
 */
@RestController
@RequestMapping("/comment/comment")
public class SyCommentController extends BaseController
{
    @Autowired
    private ISyCommentService syCommentService;

    /**
     * 查询评论列表
     */
    @PreAuthorize("@ss.hasPermi('comment:comment:list')")
    @GetMapping("/list")
    public AjaxResult list(SyComment syComment)
    {
        List<SyComment> list = syCommentService.selectSyCommentList(syComment);
        return success(list);
    }

    @PreAuthorize("@ss.hasPermi('comment:comment:list')")
    @GetMapping("/listcomment")
    public AjaxResult listComment(SyComment syComment)
    {
        List<SyComment> list = syCommentService.selectSyComment(syComment);
        return success(list);
    }

    /**
     * 导出评论列表
     */
    @PreAuthorize("@ss.hasPermi('comment:comment:export')")
    @Log(title = "评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyComment syComment)
    {
        List<SyComment> list = syCommentService.selectSyCommentList(syComment);
        ExcelUtil<SyComment> util = new ExcelUtil<SyComment>(SyComment.class);

        util.exportExcel(response, list, "评论数据");
    }


    /**
     * 获取评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('comment:comment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(syCommentService.selectSyCommentById(id));
    }

    /**
     * 新增评论
     */
    @PreAuthorize("@ss.hasPermi('comment:comment:add')")
    @Log(title = "评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyComment syComment)
    {
        return toAjax(syCommentService.insertSyComment(syComment));
    }

    /**
     * 修改评论
     */
    @PreAuthorize("@ss.hasPermi('comment:comment:edit')")
    @Log(title = "评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyComment syComment)
    {
        return toAjax(syCommentService.updateSyComment(syComment));
    }

    /**
     * 删除评论
     */
    @PreAuthorize("@ss.hasPermi('comment:comment:remove')")
    @Log(title = "评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(syCommentService.deleteSyCommentByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('comment:comment:querys')")
    @GetMapping(value = "/CommentList/{id}")
    public AjaxResult getInfos(@PathVariable("id") String id) {
        List<SyComment> list = syCommentService.selectSyCommentListByCourseId(id);
        return success(list);
    }

    @PreAuthorize("@ss.hasPermi('comment:comment:queryp')")
    @GetMapping(value = "/CommentListByProductId/{id}")
    public AjaxResult getInfosByProductId(@PathVariable("id") String id)
    {
        return success(syCommentService.selectSyCommentListByProductId(id));
    }

    @PreAuthorize("@ss.hasPermi('comment:comment:querym')")
    @GetMapping(value = "/CommentListByMicrocircleId/{id}")
    public AjaxResult getInfosByMicrocircleId(@PathVariable("id") String id)
    {
        return success(syCommentService.selectSyCommentListByMicrocircleId(id));
    }
}
